package com.dlc.beijingrfid.base;

import android.content.Context;
import com.dlc.beijingrfid.sunmi.printerhelper.utils.AidlUtil;
import com.dlc.beijingrfid.utils.StethoUtil;
import com.dlc.commonlibrary.utils.PrefUtil;
import com.dlc.commonlibrary.utils.ResUtil;
import com.dlc.commonlibrary.widget.photoSelect.PicassoImageLoader;
import com.lcodecore.tkrefreshlayout.TwinklingRefreshLayout;
import com.lcodecore.tkrefreshlayout.footer.LoadingView;
import com.lcodecore.tkrefreshlayout.header.progresslayout.ProgressLayout;
import com.lzy.imagepicker.ImagePicker;
import com.lzy.imagepicker.view.CropImageView;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.cookie.CookieJarImpl;
import com.lzy.okgo.cookie.store.SPCookieStore;
import com.tencent.bugly.crashreport.CrashReport;
import com.uuzuche.lib_zxing.activity.ZXingLibrary;
import okhttp3.OkHttpClient;

/**
 * Created by John on 2017/7/19.
 */

public class App extends BaseApplication {
    private boolean isAidl;

    public boolean isAidl() {
        return isAidl;
    }

    public void setAidl(boolean aidl) {
        isAidl = aidl;
    }

    @Override
    public void onInitAppCreate() {

    }

    @Override
    public void onCreate() {
        super.onCreate();
        ResUtil.init(this);
        PrefUtil.init(this);
        ZXingLibrary.initDisplayOpinion(this);
        initImgPicker();
        // 网络
        OkHttpClient.Builder builder = new OkHttpClient.Builder();
        StethoUtil.inspectNetwork(builder);
        builder.cookieJar(new CookieJarImpl(new SPCookieStore(this)));
        OkGo.getInstance().init(this).setOkHttpClient(builder.build());
        // Stetho调试
        StethoUtil.initStetho(this);
        TwinklingRefreshLayout.setDefaultHeader(ProgressLayout.class.getName());
        TwinklingRefreshLayout.setDefaultFooter(LoadingView.class.getName());
        CrashReport.initCrashReport(getApplicationContext(), "9f0f1611ff", false);
        isAidl = true;
        AidlUtil.getInstance().connectPrinterService(this);
    }

    public static App getApp(Context context) {
        return (App) context.getApplicationContext();
    }

    /**
     * 初始化图片选择器
     */
    private void initImgPicker(){
        ImagePicker imagePicker = ImagePicker.getInstance();
        imagePicker.setImageLoader(new PicassoImageLoader());   //设置图片加载器
        imagePicker.setShowCamera(true);  //显示拍照按钮
        imagePicker.setCrop(true);        //允许裁剪（单选才有效）
        imagePicker.setSaveRectangle(true); //是否按矩形区域保存
        imagePicker.setSelectLimit(9);    //选中数量限制
        imagePicker.setStyle(CropImageView.Style.RECTANGLE);  //裁剪框的形状
        imagePicker.setFocusWidth(800);   //裁剪框的宽度。单位像素（圆形自动取宽高最小值）
        imagePicker.setFocusHeight(800);  //裁剪框的高度。单位像素（圆形自动取宽高最小值）
        imagePicker.setOutPutX(1000);//保存文件的宽度。单位像素
        imagePicker.setOutPutY(1000);//保存文件的高度。单位像素
    }
}
